package com.burger.counter.jspValidation;

import java.util.Date;
import java.util.Hashtable;

public class RegistrationValidation {
	private String firstName;
	private String lastName;
	private String email;
	private String password1;
	private String password2;
	private String zip;
	private String dateOfBirth;
	private Hashtable<String,String> errors;
	private Integer regionData;
	

	public RegistrationValidation() 
	{
		firstName="";
		lastName="";
		email="";
		password1="";
		password2="";
		zip="";
		dateOfBirth = "";
		errors = new Hashtable<String,String>();
		regionData = 0;
	}
	public String getFirstName() 
	{
		return firstName;
	}
	public String getLastName() 
	{
		return lastName;
	}
	public String getEmail() 
	{
		return email;
	}
	
	public String getPassword1() 
	{
		return password1;
	}
	public String getPassword2() 
	{
		return password2;
	}
	public String getZip() 
	{
		return zip;
	}
	
	public String getDateOfBirth() 
	{
		return dateOfBirth;
	}
	
	public Integer getRegionData() 
	{
		return regionData;
	}

	public void setFirstName(String fname) 
	{
		firstName =fname;
	}
	
	public void setLastName(String lname) 
	{
		lastName =lname;
	}
	
	public void setEmail(String eml) 
	{
		email=eml;
	}
	
	public void setPassword1(String p1) 
	{
		password1=p1;
	}
	public void setPassword2(String p2) 
	{
		password2=p2;
	}
	public void setZip(String z) 
	{
		zip=z;
	}
	
	public void setDateOfBirth(String dob) 
	{
		dateOfBirth=dob;
	}
	
	public void setRegionData(Integer RegionData)
	{
		regionData = RegionData;
	}
	
	
	public void setErrors(String key, String msg) 
	{
		errors.put(key,msg);
	}
	
	public String getErrorMsg(String s) 
	{
		String errorMsg =(String)errors.get(s.trim());
		return (errorMsg == null) ? "":errorMsg;
	}
		
	public boolean validateForm()
	{
		boolean bool=true;
		if (firstName.equals("")) 
		{
			errors.put("firstName","Please enter your first name");
			firstName="";
			bool=false;
		}
		if (lastName.equals("")) 
		{
			errors.put("lastName","Please enter your last name");
			lastName="";
			bool=false;
		}
		if (email.equals("") || (email.indexOf('@') == -1)) 
		{
			errors.put("email","Please enter a valid email address");
			email="";
			bool=false;
		}
		if (password1.equals("") ) 
		{
			errors.put("password1","Please enter a valid password");
			password1="";
			bool=false;
		}
		if (!password1.equals("") && (password2.equals("") || 
		!password1.equals(password2))) 
		{
			errors.put("password2","Please confirm your password");
			password2="";
			bool=false;
		}
		if (zip.equals("") || zip.length() !=5 ) 
		{
			errors.put("zip","Please enter a valid zip code");
			zip="";
			bool=false;
		}
		else 
		{
			try 
			{
				Integer.parseInt(zip);
				
			}
			catch (NumberFormatException e) 
			{
				errors.put("zip","Please enter a valid zip code");
				zip="";
				bool=false;
			}
		}
		if(dateOfBirth.equals(""))
		{
			errors.put("dateOfBirth","Please enter your DateOfBirth");
			dateOfBirth = "";
			bool = false;
		}
		
		if(regionData == 0)
		{
			errors.put("regionData","Please select a Pick Up Location");
			regionData =0;
			bool = false;
		}
		return bool;
	}
		
}
